import 'package:abc/view/GradientButton.dart';
import 'package:flutter/material.dart';

// 定义按钮回调的类型别名
typedef ButtonCallback = void Function()?;

class OpenVipUnlockSheet extends StatelessWidget {

  // --- 回调参数 ---
  final ButtonCallback? onOpenMemberNow;
  final ButtonCallback? onBecomeVip;

  const OpenVipUnlockSheet({
    Key? key,
    this.onOpenMemberNow,
    this.onBecomeVip,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Padding(
        padding: MediaQuery.of(context).viewInsets, // 解决键盘遮挡问题
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            // --- 顶部标题和关闭按钮 ---
            _buildHeader(context),
            const SizedBox(height: 20),
            // --- 中间内容区 ---
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  const Text(
                    '当前章节VIP用户可查看',
                    style: TextStyle(
                      fontSize: 15,
                      color: Color(0xFF3A3A3A),
                      fontWeight: FontWeight.w400,
                      height: 1,
                    ),
                  ),
                  const SizedBox(height: 38),
                 
                  // 会员开通卡片
                  _buildVipCard(),
                  const SizedBox(height: 38),
                
                  // 支付金币按钮
                  GradientButton(
                    text: '成为会员',
                    margin: EdgeInsetsGeometry.all(0),
                    gradientColors: [Color(0xFFFFDB83), Color(0xFFFFA335)],
                    onPressed: onBecomeVip,
                  ),
                ],
              ),
            ),
            const SizedBox(height: 41),
          ],
        ),
      ),
    );
  }

  // 顶部标题和关闭按钮
  Widget _buildHeader(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(0, 16, 16, 0),
      child: Stack(
        alignment: Alignment.center,
        children: [
          const Positioned(
            child: Padding(
              padding: EdgeInsetsGeometry.only(top: 8),
              child: Text(
                '提示',
                style: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                  color: Colors.black,
                  height: 1,
                ),
              ),
            ),
          ),

          Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              InkWell(
                child: Image.asset(
                  'assets/images/ic_close.png',
                  width: 18,
                  height: 18,
                ),
                onTap: () => Navigator.of(context).pop(),
              ),
            ],
          ),
        ],
      ),
    );
  }

  // 会员开通卡片
  Widget _buildVipCard() {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.all(16.0),
      decoration: BoxDecoration(
        image: DecorationImage(
          image: AssetImage('assets/images/unlock_vip_bg.png'),
          fit: BoxFit.fill,
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text(
            '尊贵会员',
            style: TextStyle(
              fontSize: 15,
              fontWeight: FontWeight.w500,
              color: Color(0xFF85591B),
              height: 1,
            ),
          ),
          const SizedBox(height: 13),
          
           Text('开通尊贵会员，立享本章内容',style: const TextStyle(
                fontSize: 13,
                color: Color(0xFF666666),
                height: 1,
              ),),

          const SizedBox(height: 9),
          // [立即开通] 按钮
          SizedBox(
            width: 73,
            child: GradientButton(
              text: '立即开通',
              height: 27,
              margin: EdgeInsetsGeometry.all(0),
              gradientColors: [Color(0xFFFFDB83), Color(0xFFFFA335)],
              textStyle: TextStyle(
                fontSize: 14.0,
                fontWeight: FontWeight.w400,
                color: Color(0xFF85591B),
              ),
              onPressed: onOpenMemberNow,
            ),
          ),
        ],
      ),
    );
  }
}
